#region License

/*
  GShield - Game Shield
  Copyright (C) 2006-2007 WaveTech Digital Technologies, Inc.
                                http://www.wtdt.com

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#endregion License

#region Includes

using System;
using System.Drawing;
using System.Windows.Forms;
using WaveTech.GShield.Data;
using WaveTech.GShield.Engine.Factories;
using WaveTech.GShield.Manager.Properties;
using WaveTech.GShield.Model;

#endregion

namespace WaveTech.GShield.Manager
{
	public partial class ChangeRating : Form
	{
		private Game m_game;

		#region Public Properties

		public Game Game
		{
			get { return m_game; }
			set { m_game = value; }
		}

		#endregion Public Properties

		#region Constructors

		public ChangeRating()
		{
			InitializeComponent();
		}

		public ChangeRating(Game game)
		{
			m_game = game;

			InitializeComponent();
		}

		#endregion Constructors

		#region ChangeRating_Load

		private void ChangeRating_Load(object sender, EventArgs e)
		{
			if (m_game == null)
			{
				MessageBox.Show(this, "No game supplied to update ratings for. This form must close.");
				Close();
			}

			m_bannerImage.Image = BannerFactory.CreateBanner(m_bannerImage.Width,
			                                                 m_bannerImage.Height, BannerFactory.BannerStyle.WinVistaBlack,
			                                                 new Bitmap(Resources.B256x256_Games, new Size(48, 48)),
			                                                 "Game Rating Update",
			                                                 "Update a Games ESRB Rating");

			txtName.Text = m_game.Name;
			txtCompany.Text = m_game.Company;
			txtInternalName.Text = m_game.InternalName;
			txtPublisher.Text = m_game.Publisher;
			txtRating.Text = m_game.Rating;
			txtPath.Text = m_game.Path;
		}

		#endregion ChangeRating_Load

		#region btnClose_Click

		private void btnClose_Click(object sender, EventArgs e)
		{
			Close();
		}

		#endregion btnClose_Click

		#region btnSave_Click

		private void btnSave_Click(object sender, EventArgs e)
		{
			if (cboRating.SelectedItem == null)
			{
				MessageBox.Show("You must select a rating.", "Update Game Rating", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
			else
			{
				if (cboRating.SelectedItem.ToString() == "Early Childhood (EC)")
				{
					m_game.Rating = "EC";
					m_game.RatingType = (int) RatingTypes.EarlyChildhood;
				}
				else if (cboRating.SelectedItem.ToString() == "Everyone (E)")
				{
					m_game.Rating = "E";
					m_game.RatingType = (int) RatingTypes.Everyone;
				}
				else if (cboRating.SelectedItem.ToString() == "Everyone 10+ (E10+)")
				{
					m_game.Rating = "10+";
					m_game.RatingType = (int) RatingTypes.Everyone10Plus;
				}
				else if (cboRating.SelectedItem.ToString() == "Teen (T)")
				{
					m_game.Rating = "T";
					m_game.RatingType = (int) RatingTypes.Teen;
				}
				else if (cboRating.SelectedItem.ToString() == "Mature (M)")
				{
					m_game.Rating = "M";
					m_game.RatingType = (int) RatingTypes.Mature;
				}
				else if (cboRating.SelectedItem.ToString() == "Adults Only (AO)")
				{
					m_game.Rating = "AO";
					m_game.RatingType = (int) RatingTypes.AdultsOnly;
				}

				m_game.NotAGame = false;
				m_game.WasChecked = false;
				m_game.DateChecked = DateTime.Now;

				GamesDAO.Save(m_game);

				MessageBox.Show("Game " + m_game.InternalName + " was successfully updated.", "Update Game Rating",
				                MessageBoxButtons.OK,
				                MessageBoxIcon.Information);

				Close();
			}
		}

		#endregion btnSave_Click

		#region btnHelp_Click

		private void btnHelp_Click(object sender, EventArgs e)
		{
			Help.ShowHelp(this, Settings.Default.HelpFileName, HelpNavigator.TopicId,
			              Settings.Default.HelpTopics_ChangeRatingForm);
		}

		#endregion btnHelp_Click
	}
}